import request from '@/utils/request'
import { encrypt } from '@/utils/rsaEncrypt'
import qs from "qs";

export function findListByPage(params) {
  return request({
    url: 'api/users' + '?' + qs.stringify(params, {
      indices: false
    }),
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: 'api/users',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/users',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/users',
    method: 'put',
    data
  })
}

export function editUser(data) {
  return request({
    url: 'api/users/center',
    method: 'put',
    data
  })
}

export function updatePass(user) {
  const data = {
    oldPass: encrypt(user.oldPass),
    newPass: encrypt(user.newPass)
  }
  return request({
    url: 'api/users/updatePass/',
    method: 'post',
    data
  })
}

export function updateEmail(form) {
  const data = {
    password: encrypt(form.pass),
    email: form.email
  }
  return request({
    url: 'api/users/updateEmail/' + form.code,
    method: 'post',
    data
  })
}

/*export function checkuserNicknameData(data) {
  return request({
    url: 'api/users/checkuserNicknameData',
    method: 'post',
    data
  })
}*/

export function resetPass(data) {
  return request({
    url: 'api/users/resetPass',
    method: 'post',
    data
  })
}

export function findUserByUserName(username) {
  return request({
    url: 'api/users/findUserByUserName?username=' + username,
    method: 'get'
  })
}

export function checkRepeatuserName(data) {
  return request({
    url: 'api/users/checkRepeatuserName',
    method: 'post'
  })
}

export function checkuserName(data) {
  return request({
    url: 'api/appUser/checkuserName',
    method: 'post'
  })
}

export function isResetPassWord(username) {
  return request({
    url: 'api/users/isFirstLogin?username=' + username,
    method: 'get'
  })
}
export default { add, edit, del, resetPass, findUserByUserName, checkRepeatuserName, findListByPage, isResetPassWord }
